package com.baizhi.cmfz.controller;

import com.baizhi.cmfz.entity.UserDTO;
import com.baizhi.cmfz.service.UserService;
import com.baizhi.cmfz.service.UserThreadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@RequestMapping("/user")
@Controller
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private UserThreadService userThreadService;

    @RequestMapping("/showPageUser")
    @ResponseBody
    public Map showPageUser(int page, int limit){
        return userService.showPageUser(page,limit);
    }
    @RequestMapping("/showSex")
    @ResponseBody
    public List<UserDTO> showSex(){
        return userService.showSex();
    }

    @RequestMapping("/showSexs")
    @ResponseBody
    public List<Map> showSexs(){
        return userService.showSexs();
    }

    @RequestMapping("/showCity")
    @ResponseBody
    public List<Map> showCity(){
        return userService.showCity();
    }

    @RequestMapping("/showDate")
    @ResponseBody
    public Map showDate(){
        return userService.showDate();
    }

    @RequestMapping("/showThread")
    @ResponseBody
    public Map showThread() throws InterruptedException {
            long start = System.currentTimeMillis();
            Map map = userService.selectByThread();
            long end = System.currentTimeMillis();
            System.out.println(end-start+"ms");
            return map;
        }
        /**
         * 无优化
         * @return
         */
        @RequestMapping("/selectAllCount")
        @ResponseBody
        public Map selectAllCount() throws InterruptedException {
            long start = System.currentTimeMillis();
            Map map = userThreadService.showAllCount();
            long end = System.currentTimeMillis();
            System.out.println(end-start+"ms");
            return map;
        }
}
